/*
 * Main.fx
 *
 * Created on 19.03.2010, 18:16:51
 */

package javafx191labs.kprokin.lab01;

import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.shape.Line;
import javafx.scene.Group;
import javafx.animation.Timeline;
import javafx.ext.swing.SwingSlider;
import javafx.scene.effect.Glow;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Circle;
import javafx.scene.control.Button;
import javafx.scene.shape.Polyline;
import javafx.scene.effect.GaussianBlur;
import javafx.ext.swing.SwingLabel;


/**
 * @author Kirill
 */

// place your code here
var x_1i4: Integer;
var y_1i4: Integer;
var x_2i3: Integer;
var y_2i3: Integer;
y_2i3 = 40;
var c1x1 = 0;
var c1y1 = 0;
var c1x2 = 0;
var c1y2 = 0;

var c2x1 = 0;
var c2y1 = 0;
var c2x2 = 0;
var c2y2 = 0;

var c3x1 = 0;
var c3y1 = 0;
var c3x2 = 0;
var c3y2 = 0;

var c4x1 = 0;
var c4y1 = 0;
var c4x2 = 0;
var c4y2 = 0;
var fuelopacity = 1;
var fuelcolor1 = Color.BLUE;
var fuelcolor2 = Color.RED;
var fuelcolor3 = Color.GRAY;
var fuelcolor4 = Color.RED;

var myTimeline = Timeline {
	repeatCount: Timeline.INDEFINITE;
        rate: bind mySlider.value

        keyFrames : [
                at (0ms){
                    c1x1 => 0;
                    c1y1 => 0;
                    c1x2 => 0;
                    c1y2 => 0;
                    y_2i3 => 40;
                    fuelcolor1 => Color.BLUE;
                    fuelcolor2 => Color.BLUE;
                    fuelcolor3 => Color.RED;
                    fuelcolor4 => Color.RED;  

                    c2x1 => 0;
                    c2y1 => 0;
                    c2x2 => 0;
                    c2y2 => 0;

                    c3x1 => 0;
                    c3y1 => 0;
                    c3x2 => 0;
                    c3y2 => 0;

                    c4x1 => 0;
                    c4y1 => 0;
                    c4x2 => 0;
                    c4y2 => 0;
                },
                at (300ms){
                    c1x1 => 7;
                    c1y1 => 7;
                    c1x2 => 0;
                    c1y2 => 0;
                    c2x1 => 0;
                    c2y1 => 0;
                    c2x2 => 0;
                    c2y2 => 0;

                    c3x1 => 0;
                    c3y1 => 0;
                    c3x2 => -7;
                    c3y2 => 7;
                },
                at (700ms){
                    c1x1 => 7;
                    c1y1 => 7;

                    c3x2 => -7;
                    c3y2 => 7;
                },
                at (1000ms){
                    y_1i4 => 40;
                    y_2i3 => 0;
                    fuelcolor1 => Color.BLUE;
                    fuelcolor2 => Color.RED;
                    fuelcolor3 => Color.GRAY;
                    fuelcolor4 => Color.RED;
                   // fuelopacity => 0.7;
                    c1x1 => 0;
                    c1y1 => 0;
                    c3x1 => 0;
                    c3y1 => 0;
                    c3x2 => 0;
                    c3y2 => 0;

                    c4x2 => 0;
                    c4y2 => 0;
                },
                at(1300ms){
                    c3x1 => 7;
                    c3y1 => 7;

                    c4x2 => -7;
                    c4y2 => 7;
                },
                at(1700ms){
                    c3x1 => 7;
                    c3y1 => 7;

                    c4x2 => -7;
                    c4y2 => 7;
                },
                at (2000ms){                    
                    c2x2 => 0;
                    c2y2 => 0;
                    c3x1 => 0;
                    c3y1 => 0;
                    c4x1 => 0;
                    c4y1 => 0;
                    c4x2 => 0;
                    c4y2 => 0;
                    y_1i4 => 0;
                    y_2i3 => 40;
                    fuelcolor1 => Color.RED;
                    fuelcolor2 => Color.RED;
                    fuelcolor3 => Color.BLUE;
                    fuelcolor4 => Color.GRAY;
                    //fuelopacity => 1;
                },
                at (2300ms){
                    c2x2 => -7;
                    c2y2 => 7;

                    c4x1 => 7;
                    c4y1 => 7;
                },
                at (2700ms){
                    c2x2 => -7;
                    c2y2 => 7;

                    c4x1 => 7;
                    c4y1 => 7;
                },
                at (3000ms){
                    y_1i4 => 40;
                    y_2i3 => 0;
                    fuelcolor1 => Color.RED;
                    fuelcolor2 => Color.GRAY;
                    fuelcolor3 => Color.RED;
                    fuelcolor4 => Color.BLUE;
                   // fuelopacity => 1;
                    c1x2 => 0;
                    c1y2 => 0;

                    c2x1 => 0;
                    c2y1 => 0;
                    c2x2 => 0;
                    c2y2 => 0;

                    c4x1 => 0;
                    c4y1 => 0;
                },
                at (3300ms){
                    c1x2 => -7;
                    c1y2 => 7;

                    c2x1 => 7;
                    c2y1 => 7;
                },
                at (3700ms){
                    c1x2 => -7;
                    c1y2 => 7;

                    c2x1 => 7;
                    c2y1 => 7;
                },
                at (4000ms){
                    y_1i4 => 0;
                    y_2i3 => 40;
                    c1x2 => 0;
                    c1y2 => 0;

                    c2x1 => 0;
                    c2y1 => 0;
                    c2x2 => 0;
                    c2y2 => 0;
                    fuelcolor1 => Color.GRAY;
                    fuelcolor2 => Color.BLUE;
                    fuelcolor3 => Color.RED;
                    fuelcolor4 => Color.RED;
                   // fuelopacity => 0.1;
                }
	]
};
var mySlider: SwingSlider = SwingSlider {
        layoutX: 10;
        layoutY: 10;
	minimum: 1;
	maximum: 400;
	value: 60
	vertical: false;
}

myTimeline.play();


Stage {
	title : "MyApp"
	scene: Scene {
		width: 640
		height: 480
		content: [
Polyline {
	points : [ 30,100, 30,300, 350,300,
        350,100, 330,100, 330,80, 150,80, 130,75,
        110,75, 110,65, 95,65, 95,75, 80,75, 50,80,
        30,80, 30,100]
	strokeWidth: 4.0
	stroke: Color.RED
        fill: LinearGradient {
	startX : 0.0
	startY : 0.5
	endX : 0.0
	endY : 1.0
	stops: [
		Stop {
			color : Color.WHITE
			offset: 0.5
		},
		Stop {
			color : Color.YELLOW
			offset: 1.0
		},
	]
}
        opacity: 0.8;
        effect: GaussianBlur {
	radius: bind mySlider.value / 20;
}
}
SwingLabel {
        layoutX: 10;
        layoutY: 40;
        width: 100;
	//text: "Label"
        text: bind "{ myTimeline.rate*15} rmp";
}

Group {//цилиндр 1
	content: [
Group {//топливо
	content: [
                Rectangle {
	x: 50, y: 60
	width: 35, height: 40	
        fill: bind fuelcolor1;
        opacity: bind fuelopacity;
}
	]
}//топливо
Group {//поршень
	content: [
		Rectangle {
	x: 50, y: 60
	width: 35, height: 40
	fill: LinearGradient {
	startX : 0.0
	startY : 0.0
	endX : 1.0
	endY : 0.0
	stops: [
		Stop {
			color : Color.GRAY
			offset: 0.0
		},
		Stop {
			color : Color.WHITE
			offset: 1.0
		},

	]
}

}
Line {
	startX: 60, startY: 100
	endX: 57, endY: 160        
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 75, startY: 100
	endX: 78, endY: 160
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 50, startY: 68
	endX: 85, endY: 68
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 74
	endX: 85, endY: 74
	strokeWidth: 2
	stroke: Color.BLACK
}
Circle {
	centerX: 67.5, centerY: 86
	radius: 6
	fill: Color.BLACK
}


	]
         translateX: bind x_1i4;
         translateY: bind y_1i4;
}//поршень
Group {
	content: [
		Line {
	startX: 50, startY: 60
	endX: 65, endY: 53
	strokeWidth: 3
	stroke: Color.BLUE
}
	
]
translateX: bind c1x1;
translateY: bind c1y1;
}//клапан впускной
Group {
	content: [
		Line {
	startX: 85, startY: 60
	endX: 70, endY: 53
	strokeWidth: 3
	stroke: Color.RED
}
	]
translateX: bind c1x2;
translateY: bind c1y2;
}//клапан выпускной
Group {//стенки цилиндра
	content: [
Line {
	startX: 67.5, startY: 45
	endX: 67.5, endY: 60
	strokeWidth: 1
	stroke: Color.ORANGE
        effect: Glow {
	level: 1
}
}
Line {
	startX: 67.5, startY: 51
	endX: 67.5, endY: 57
	strokeWidth: 3
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 60
	endX: 50, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 85, startY: 60
	endX: 85, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}	
	]
}//стенки цилиндра		
	]
        translateX: 0
        translateY: 70
}//цилиндр 1
Group {//цилиндр 2
	content: [
Group {//топливо
	content: [
                Rectangle {
	x: 50, y: 60
	width: 35, height: 40
        fill: bind fuelcolor2;
        opacity: bind fuelopacity;
}
	]
}//топливо
Group {//поршень
	content: [
		Rectangle {
	x: 50, y: 60
	width: 35, height: 40
	fill: LinearGradient {
	startX : 0.0
	startY : 0.0
	endX : 1.0
	endY : 0.0
	stops: [
		Stop {
			color : Color.GRAY
			offset: 0.0
		},
		Stop {
			color : Color.WHITE
			offset: 1.0
		},

	]
}

}
Line {
	startX: 60, startY: 100
	endX: 57, endY: 160
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 75, startY: 100
	endX: 78, endY: 160
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 50, startY: 68
	endX: 85, endY: 68
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 74
	endX: 85, endY: 74
	strokeWidth: 2
	stroke: Color.BLACK
}
Circle {
	centerX: 67.5, centerY: 86
	radius: 6
	fill: Color.BLACK
}


	]
         translateX: bind x_2i3;
         translateY: bind y_2i3;
}//поршень
Group {
	content: [
		Line {
	startX: 50, startY: 60
	endX: 65, endY: 53
	strokeWidth: 3
	stroke: Color.BLUE
}

]
translateX: bind c2x1;
translateY: bind c2y1;
}//клапан впускной
Group {
	content: [
		Line {
	startX: 85, startY: 60
	endX: 70, endY: 53
	strokeWidth: 3
	stroke: Color.RED
}
	]
translateX: bind c2x2;
translateY: bind c2y2;
}//клапан выпускной
Group {//стенки цилиндра
	content: [
Line {
	startX: 67.5, startY: 45
	endX: 67.5, endY: 60
	strokeWidth: 1
	stroke: Color.ORANGE
        effect: Glow {
	level: 1
}
}
Line {
	startX: 67.5, startY: 51
	endX: 67.5, endY: 57
	strokeWidth: 3
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 60
	endX: 50, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 85, startY: 60
	endX: 85, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}
	]
}//стенки цилиндра
	]
        translateX: 70
        translateY: 70
}//цилиндр 2
Group {//цилиндр 3
	content: [
Group {//топливо
	content: [
                Rectangle {
	x: 50, y: 60
	width: 35, height: 40
        fill: bind fuelcolor3;
        opacity: bind fuelopacity;
}
	]
}//топливо
Group {//поршень
	content: [
		Rectangle {
	x: 50, y: 60
	width: 35, height: 40
	fill: LinearGradient {
	startX : 0.0
	startY : 0.0
	endX : 1.0
	endY : 0.0
	stops: [
		Stop {
			color : Color.GRAY
			offset: 0.0
		},
		Stop {
			color : Color.WHITE
			offset: 1.0
		},

	]
}

}
Line {
	startX: 60, startY: 100
	endX: 57, endY: 160
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 75, startY: 100
	endX: 78, endY: 160
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 50, startY: 68
	endX: 85, endY: 68
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 74
	endX: 85, endY: 74
	strokeWidth: 2
	stroke: Color.BLACK
}
Circle {
	centerX: 67.5, centerY: 86
	radius: 6
	fill: Color.BLACK
}


	]
         translateX: bind x_2i3;
         translateY: bind y_2i3;
}//поршень
Group {
	content: [
		Line {
	startX: 50, startY: 60
	endX: 65, endY: 53
	strokeWidth: 3
	stroke: Color.BLUE
}

]
translateX: bind c3x1;
translateY: bind c3y1;
}//клапан впускной
Group {
	content: [
		Line {
	startX: 85, startY: 60
	endX: 70, endY: 53
	strokeWidth: 3
	stroke: Color.RED
}
	]
translateX: bind c3x2;
translateY: bind c3y2;
}//клапан выпускной
Group {//стенки цилиндра
	content: [
Line {
	startX: 67.5, startY: 45
	endX: 67.5, endY: 60
	strokeWidth: 1
	stroke: Color.ORANGE
        effect: Glow {
	level: 1
}
}
Line {
	startX: 67.5, startY: 51
	endX: 67.5, endY: 57
	strokeWidth: 3
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 60
	endX: 50, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 85, startY: 60
	endX: 85, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}
	]
}//стенки цилиндра
	]
        translateX: 140
        translateY: 70
}//цилиндр 3
Group {//цилиндр 4
	content: [
Group {//топливо
	content: [
                Rectangle {
	x: 50, y: 60
	width: 35, height: 40
        fill: bind fuelcolor4;
        opacity: bind fuelopacity;
}
	]
}//топливо
Group {//поршень
	content: [
		Rectangle {
	x: 50, y: 60
	width: 35, height: 40
	fill: LinearGradient {
	startX : 0.0
	startY : 0.0
	endX : 1.0
	endY : 0.0
	stops: [
		Stop {
			color : Color.GRAY
			offset: 0.0
		},
		Stop {
			color : Color.WHITE
			offset: 1.0
		},

	]
}

}
Line {
	startX: 60, startY: 100
	endX: 57, endY: 160
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 75, startY: 100
	endX: 78, endY: 160
	strokeWidth: 4;
	stroke: Color.GRAY;
}
Line {
	startX: 50, startY: 68
	endX: 85, endY: 68
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 74
	endX: 85, endY: 74
	strokeWidth: 2
	stroke: Color.BLACK
}
Circle {
	centerX: 67.5, centerY: 86
	radius: 6
	fill: Color.BLACK
}


	]
         translateX: bind x_1i4;
         translateY: bind y_1i4;
}//поршень
Group {
	content: [
		Line {
	startX: 50, startY: 60
	endX: 65, endY: 53
	strokeWidth: 3
	stroke: Color.BLUE
}

]
translateX: bind c4x1;
translateY: bind c4y1;
}//клапан впускной
Group {
	content: [
		Line {
	startX: 85, startY: 60
	endX: 70, endY: 53
	strokeWidth: 3
	stroke: Color.RED
}
	]
translateX: bind c4x2;
translateY: bind c4y2;
}//клапан выпускной
Group {//стенки цилиндра
	content: [
Line {
	startX: 67.5, startY: 45
	endX: 67.5, endY: 60
	strokeWidth: 1
	stroke: Color.ORANGE
        effect: Glow {
	level: 1
}
}
Line {
	startX: 67.5, startY: 51
	endX: 67.5, endY: 57
	strokeWidth: 3
	stroke: Color.BLACK
}
Line {
	startX: 50, startY: 60
	endX: 50, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}
Line {
	startX: 85, startY: 60
	endX: 85, endY: 120
	strokeWidth: 2
	stroke: Color.BLACK
}
	]
}//стенки цилиндра
	]
        translateX: 210
        translateY: 70
}//цилиндр 4

Button {
	text: "Pause"
        layoutX:230;
        layoutY:10;
	action: function() {
                if (myTimeline.paused == true){
                    myTimeline.play();
                }
                else{
                    myTimeline.pause();
                }                                
	}
}



mySlider,




                        ]

	}

}
